import {
  addDir,
  addFlowApply,
  addOutApply,
  addPreDownload,
  addPrivateFileDownloadApply,
  addShareApply,
  applyAudit,
  copyFile,
  deleteFileOrDir,
  getEditLinkPath,
  getPreviewLinkPath,
  markFileMostUse,
  moveFile,
  queryDirTreeList,
  queryFileDir,
  queryMyFiles,
  updateDir,
  updateFileMostUse,
  updateFileShare,
  upload,
  uploadFiles,
} from '@/services/workspace';

import {queryOrgList, queryTreeOrgList,queryUserList,} from '@/services/system/sysRole';


export default {
  namespace: 'userSelectModel',

  state: {

    //组织树
    orgTree: [],
    //组织下的用户
    userList: [],
  },


  effects: {
    * queryOrgTree({payload}, {call, put}) {
      const response = yield call(queryTreeOrgList, payload);
      if (response.result == 'fail') {
        return;
      }
      yield put({
        type: 'saveOrgTree',
        payload: response,
      });

    },
    * queryUserList({payload}, {call, put}) {
      const response = yield call(queryUserList, payload);
      if (response.result == 'fail') {
        return;
      }
      yield put({
        type: 'saveUserList',
        payload: response,
      });

    },

  },

  reducers: {

    saveOrgTree(state, action) {
      let oldTree = action.payload.data;
      let newTree = [];


      return {
        ...state,
        orgTree: action.payload.data,
      };
    },
    saveUserList(state, action) {
      return {
        ...state,
        userList: action.payload.data,
      };
    },


  },
};
